home *** CD-ROM | disk | FTP | other *** search
- /* Main of the new trial run */
-
- #include "LPR.H"
- #include "TCPStream.H"
- #include "BackGrounder.H"
- #include "lprProtos.H"
-
-
- void DoWindowActivate(WindowPtr window, Boolean activ);
- void DoWindowUpdate(WindowPtr window);
- void DoWindowClick(WindowPtr window, EventPtr event);
- void DoWindowGrow(WindowPtr window, Point mouse);
- void DoWindowZoom(WindowPtr window, Boolean in);
- void DoWindowKey(WindowPtr window, EventPtr event);
- LongWord GetSleep(void);
- void DoIdles(integer *state);
-
- void main()
- {
- Initialise();
- UnloadSeg(Initialise);
-
- SetCursor(&arrow);
-
- haveWaitEvnt = FALSE;
-
- while (TRUE)
- MainEvents(everyEvent);
- }
-
-
-
- void WaitForEvent(integer evtMask, EventPtr event)
- {
- Boolean gotEvent;
-
- do {
- CursorAdjust(event->where, cursRgn); /* update cursor */
-
- if (haveWaitEvnt)
- gotEvent = WaitNextEvent(evtMask, event, GetSleep(), cursRgn);
- else
- {
- SystemTask(); /* run drivers */
- gotEvent = GetNextEvent(evtMask, event);
- }
-
- if (!gotEvent)
- {
- if (event->what == nullEvent)
- {
- integer junk;
- IsDialogEvent(event); /* flick TE's in dialogs */
- DoIdles(&junk); /* run the idle procedures */
- }
- }
- }
- while (!gotEvent);
- }
-
- integer MainEvents(integer evtMask)
- {
- integer part, junk;
- WindowPtr window;
- EventRecord event;
-
- WaitForEvent(evtMask, &event);
-
- if ( (event.what == keyDown) && (event.modifiers & cmdKey) )
- {
- if ( (event.message & 0x7F) == '.' )
- stopped = TRUE;
- else
- {
- }
- return TRUE;
- }
-
- if ( IsDialogEvent(&event) )
- {
- if ( HandleDEvent(&event) )
- return FALSE;
- }
-
- switch (event.what)
- {
- case mouseDown :
- switch(part = FindWindow(event.where, &window))
- {
- case inMenuBar :
- break;
- case inSysWindow :
- SystemClick(&event, window);
- break;
- case inDrag :
- case inGrow :
- case inGoAway :
- case inContent :
- case inZoomIn :
- case inZoomOut :
- break;
- }
- break;
- case keyDown:
- case autoKey:
- break;
- case activateEvt :
- break;
- case updateEvt :
- break;
- case osEvt:
- switch ((event.message >> 24) & 0xFF) /* high byte of message */
- {
- case mouseMovedMessage:
- CursorAdjust(event.where, cursRgn); /* update cursor */
- DoIdles(&junk);
- break;
- case suspendResumeMessage:
- inBackground = ((event.message & resumeFlag) == 0);
- break;
- default:
- break;
- }
- break;
- default :
- break;
- }
-
- return FALSE;
- }
-
-
- void Exit()
- {
- ExitTCPS();
-
- ExitToShell();
- }
-
- void CursorAdjust(Point where, RgnHandle crsRgn)
- {
- }
-
-
- void DoIdles(integer *state)
- {
- EventRecord event;
-
- RunBackground();
- SystemTask(); /* run drivers */
- if ( EventAvail(everyEvent, &event) )
- MainEvents(everyEvent);
- if (stopped && *state > 0) *state = -1;
-
- }
-
- stdWinHand IsAppWindow(WindowPtr window)
- {
- integer windowKind;
- stdWinHand sHand;
-
- if ( !window ) return NIL;
-
- /* check that the window is in our applications Zone */
- if ( PtrZone((Ptr)window) != ApplicZone() )
- return NIL; /* not in our zone so not one of ours */
-
- windowKind = ((WindowPeek)window)->windowKind;
- if ( windowKind < 8 && windowKind != 2 )
- return NIL;
-
- sHand = (stdWinHand)StripAddress((Ptr)GetWRefCon(window));
-
- /* check that the refCon is in our applications Zone, if *
- * the window is this should be too, but you never know */
- if ( HandleZone((Handle)sHand) != ApplicZone() )
- return NIL; /* something screwey here! */
-
- return sHand;
- }
-
-
- Boolean IsDAWindow(WindowPtr window)
- {
- integer windowKind;
-
- if ( !window ) return FALSE;
-
- windowKind = ((WindowPeek)window)->windowKind;
- if ( windowKind < 0 )
- return TRUE;
-
- return FALSE;
- }
-
-
- LongWord GetSleep()
- {
- if ( !inBackground )
- {
- if ( IsAppWindow(FrontWindow()) )
- return (LongInt)GetCaretTime();
- else
- return 0x3FF;
- }
-
- return 0x7FFFFFFFL; /* if we are in the backgound we can sleep forever */
- }
-
-
- /* Returns the update region in local coordinates */
- void GetLocalUpdateRgn(WindowPtr window, RgnHandle localRgn)
- {
- CopyRgn(((WindowPeek) window)->updateRgn, localRgn); /* save old update region */
- OffsetRgn(localRgn, window->portBits.bounds.left, window->portBits.bounds.top);
- } /* GetLocalUpdateRgn */
-
-
- /************************************************************************
- ************************************************************************/
- Boolean noMenus = FALSE;
- void WaitForState(integer *state);
- void WaitForState(integer *state)
- {
- extern Boolean Quitable;
- Boolean quit_back = Quitable;
- Quitable = FALSE;
- noMenus = TRUE;
- while (*state)
- {
- MainEvents(everyEvent);
- RunBackground();
- }
- noMenus = FALSE;
- }
-